﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cn.Edwon.Web.Support;
using Cn.Cellula.Biz.Port;
using Cn.Edwon.Spring;
using System.Reflection;
using Cn.Cellula.Model.System;
using System.Text;
using Cn.Cellula.Client;
using Cn.Cellula.Model.Content;
using Cn.Cellula.Biz;
using Cn.Edwon.Data;

namespace Cn.Cellula.Website.Admin.Item {
    public partial class ItemQuery : PageSupport {
        IItemBiz biz = BizFactory.Get<IItemBiz>();
        protected void Page_Load(object sender, EventArgs e) {
            if (!Page.IsPostBack) {
                InitForm();
                LoadQueryForm();
            }
        }
        private void InitForm() {
            this.ddl_Category.DataSource = BizFactory.Get<ICategoryBiz>().LoadCatalog2ListItem(this.OwnerKey, null, "...", null, true);
            this.ddl_Category.DataTextField = "Text";
            this.ddl_Category.DataValueField = "Value";
            this.ddl_Category.DataBind();
            if (!String.IsNullOrEmpty(Request.QueryString["cid"]))
                this.ddl_Category.SelectedValue = Request.QueryString["cid"];
        }

        private void LoadQueryForm() {
            IList<String> atlKeyList = new List<String>();
            this.lab_QueryForm.Text = ClientBiz.LoadItemAtlQueryForm(this.ddl_Category.SelectedValue,ref atlKeyList,this.Power);
            this.hid_AtlKeys.Value = ClientBiz.ConvertList2String(atlKeyList);
        }
        private String FilterQueryData(String rVal) {
            if (String.IsNullOrEmpty(rVal))
                return "";
            else
                return rVal.Replace(":", "").Replace(",", "");
        }


        protected void ddl_Category_SelectedIndexChanged(object sender, EventArgs e) {
            LoadQueryForm();
            this.lab_QueryList.Text = "";
        }
    }
}